package com.sg.service.biz.pbff.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.sg.common.exception.Assert;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.pbff.req.*;
import com.sg.dto.biz.pbff.res.*;
import com.sg.service.biz.pbff.PlfAuthService;
import com.sg.service.biz.pbff.nb.NbPlfAuth;
import com.wicket.okrframework.integration.*;
import com.wicket.okrframework.integration.dto.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class PlfAuthServiceImpl implements PlfAuthService {

    @Resource
    com.sg.service.biz.framework.PlfAuthService fwBasePlfAuthClient;
    @Resource
    com.sg.service.biz.framework.InductionRecordService fwBaseInductionRecordClient;
    @Resource
    com.sg.service.biz.framework.PowerService fwBasePowerClient;
    @Resource
    com.sg.service.biz.framework.DivineDataService fwBaseDivineDataClient;
    @Resource
    NbPlfAuth nbPlfAuth;
    @Resource
    com.sg.service.biz.framework.RoleService fwBaseRoleClient;
    @Resource
    com.sg.service.biz.framework.MemberService fwBaseMemberClient;
    @Resource
    private RedisUtil redisUtil;

    /**
     * B1-1查询角色授权列表（平台）[585]
     * gen by moon at 8/20/2022, 6:00:11 PM
     */
    @Trace(operationName = "B1-1查询角色授权列表（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryPltRoleAuthListRespDto queryPltRoleAuthList(BffQueryPltRoleAuthListReqDto reqDto) {


        QueryPltRoleAuthListRespDto queryPltRoleAuthListRespDto_1 = null;
        BatchQueryInductionRecordListComRespDto batchQueryInductionRecordListComRespDto_1 = null;
//步骤0: D1-1查询角色授权列表 - queryPltRoleAuthList
        QueryPltRoleAuthListRespDto queryPltRoleAuthListRespDto = null;
        QueryPltRoleAuthListReqDto queryPltRoleAuthListReqDto = new QueryPltRoleAuthListReqDto();
        if (reqDto != null) {
            queryPltRoleAuthListReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:33969_1
            queryPltRoleAuthListReqDto.setIsArchive(reqDto.getIsArchive());//sourceId:33970_1
            queryPltRoleAuthListReqDto.setRoleType(reqDto.getRoleType());//sourceId:33971_1
            queryPltRoleAuthListReqDto.setPlatformData(reqDto.getPlatformData());//sourceId:33972_1
        }

        /*D1-1查询角色授权列表[1434]   */
        Assert.isNull(queryPltRoleAuthListReqDto.getAuthorizedObject(), "B1-1查询角色授权列表（平台）-D1-1查询角色授权列表-授权对象ID不能为空", false);
        Assert.isNull(queryPltRoleAuthListReqDto.getIsArchive(), "B1-1查询角色授权列表（平台）-D1-1查询角色授权列表-是否存档不能为空", false);
        queryPltRoleAuthListRespDto = fwBasePlfAuthClient.queryPltRoleAuthList(queryPltRoleAuthListReqDto).getData();

        queryPltRoleAuthListRespDto_1 = queryPltRoleAuthListRespDto;

//步骤1: D1-3批量查询就职记录列表（公共） - batchQueryInductionRecordListCom
        BatchQueryInductionRecordListComRespDto batchQueryInductionRecordListComRespDto = null;
        if (queryPltRoleAuthListRespDto != null && queryPltRoleAuthListRespDto != null && queryPltRoleAuthListRespDto.getPlfAuthList() != null && queryPltRoleAuthListRespDto.getPlfAuthList().size() > 0) {
            BatchQueryInductionRecordListComReqDto batchQueryInductionRecordListComReqDto = new BatchQueryInductionRecordListComReqDto();
            if (queryPltRoleAuthListRespDto != null) {
                batchQueryInductionRecordListComReqDto.setPerOrgInductionRecordList(queryPltRoleAuthListRespDto.getPlfAuthList().stream().map(item -> item.getOperationInductionId())
                        .collect(Collectors.toList()));//sourceId:28433_1
            }

            /*D1-3批量查询就职记录列表（公共）[602]   */

            batchQueryInductionRecordListComRespDto = fwBaseInductionRecordClient.batchQueryInductionRecordListCom(batchQueryInductionRecordListComReqDto).getData();

            batchQueryInductionRecordListComRespDto_1 = batchQueryInductionRecordListComRespDto;
        }

        BffQueryPltRoleAuthListRespDto retData = new BffQueryPltRoleAuthListRespDto();
        //数据集融合
        if (queryPltRoleAuthListRespDto_1 != null && !CollectionUtil.isEmpty(queryPltRoleAuthListRespDto_1.getPlfAuthList())) {
            for (PlfAuthDto plfAuthDto : queryPltRoleAuthListRespDto_1.getPlfAuthList()) {
                BffPlfAuthDto retElm = new BffPlfAuthDto();
                if (queryPltRoleAuthListRespDto_1 != null) {
                    retElm.setPlatformAuthorizeId(plfAuthDto.getPlatformAuthorizeId());//sourceId:15291_2
                    retElm.setAuthorizedContentId(plfAuthDto.getAuthorizedContentId());//sourceId:15293_2
                    retElm.setSubjectLifeCycle(plfAuthDto.getSubjectLifeCycle());//sourceId:15365_2
                    retElm.setOperationInductionId(plfAuthDto.getOperationInductionId());//sourceId:15303_2
                    retElm.setOperateTime(plfAuthDto.getOperateTime());//sourceId:15304_2
                    retElm.setIsIdentity(plfAuthDto.getIsIdentity());//sourceId:15368_2
                    retElm.setRoleCode(plfAuthDto.getRoleCode());//sourceId:15292_2
                    retElm.setRoleName(plfAuthDto.getRoleName());//sourceId:15294_2
                }
                retData.getPlfAuthList().add(retElm);
                if (batchQueryInductionRecordListComRespDto_1 != null) {
                    for (PerOrgInductionRecordDto perOrgInductionRecordDto : batchQueryInductionRecordListComRespDto_1.getPerOrgInductionRecordList()) {
                        if (perOrgInductionRecordDto.getInductionRecordId().equals(plfAuthDto.getOperationInductionId())) {
                            if (batchQueryInductionRecordListComRespDto_1 != null) {
                                retElm.setUserId(perOrgInductionRecordDto.getUserId());//sourceId:38748_2
                                retElm.setUserFace(perOrgInductionRecordDto.getUserFace());//sourceId:38751_2
                                retElm.setIdCardName(perOrgInductionRecordDto.getIdCardName());//sourceId:38749_2
                                retElm.setNickName(perOrgInductionRecordDto.getNickName());//sourceId:38750_2
                            }
                        }
                    }
                }

            }
        }//sourceId:33973_1


        retData.setPageNum(queryPltRoleAuthListRespDto.getPageNum());
        retData.setPageSize(queryPltRoleAuthListRespDto.getPageSize());
        retData.setTotal(queryPltRoleAuthListRespDto.getTotalNum());
        retData.setIsLastPage((Math.ceil(Double.valueOf(queryPltRoleAuthListRespDto.getTotalNum()) / Double.valueOf(queryPltRoleAuthListRespDto.getPageSize()))) <= retData.getPageNum());


        return retData;
    }

    /**
     * B1-2查询可授权权限列表（平台）[1127]
     * gen by moon at 8/10/2022, 3:43:02 AM
     */
    @Trace(operationName = "B1-2查询可授权权限列表（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryFilterPltPowerAuthListRespDto queryFilterPltPowerAuthList(BffQueryFilterPltPowerAuthListReqDto reqDto) {


        CheckCollectionRemoveExistingDataRespDto collectionRemoveExistingDataRes_1 = null;
//步骤0: D1-2查询权限列表 - queryPowerList
        QueryPowerListRespDto queryPowerListRespDto = null;
        QueryPowerListReqDto queryPowerListReqDto = new QueryPowerListReqDto();
        queryPowerListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:29903_1
        if (reqDto != null) {
            queryPowerListReqDto.setStrategyType(reqDto.getStrategyType());//sourceId:35232_1
        }

        /*D1-2查询权限列表（查全部）[555]   */
        Assert.isNull(queryPowerListReqDto.getStrategyType(), "B1-2查询可授权权限列表（平台）-D1-2查询权限列表（查全部）-分配策略不能为空", false);
        Assert.isNull(queryPowerListReqDto.getSubjectLifeCycle(), "B1-2查询可授权权限列表（平台）-D1-2查询权限列表（查全部）-主体生命周期不能为空", false);
        queryPowerListRespDto = fwBasePowerClient.queryPowerList(queryPowerListReqDto).getData();


//步骤1: D1-1查询平台授权范围列表 - queryPlfAuthList
        QueryPlfAuthListRespDto queryPlfAuthListRespDto = null;
        QueryPlfAuthListReqDto queryPlfAuthListReqDto = new QueryPlfAuthListReqDto();
        queryPlfAuthListReqDto.setTypeCode("AUTH");//sourceId:35259_1
        queryPlfAuthListReqDto.setIsArchive("FALSE");//sourceId:35261_1
        if (reqDto != null) {
            queryPlfAuthListReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35260_1
        }

        /*D1-1查询平台授权范围列表（已有）[580]   */
        Assert.isNull(queryPlfAuthListReqDto.getTypeCode(), "B1-2查询可授权权限列表（平台）-D1-1查询平台授权范围列表（已有）-授权内容类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReqDto.getAuthorizedObject(), "B1-2查询可授权权限列表（平台）-D1-1查询平台授权范围列表（已有）-授权对象ID不能为空", false);
        Assert.isNull(queryPlfAuthListReqDto.getIsArchive(), "B1-2查询可授权权限列表（平台）-D1-1查询平台授权范围列表（已有）-是否存档不能为空", false);
        queryPlfAuthListRespDto = fwBasePlfAuthClient.queryPlfAuthList(queryPlfAuthListReqDto).getData();


//步骤2: D检查集合去除已存在数据 - checkCollectionRemoveExistingData
        //ModelCode: collectionRemoveExistingData
        CheckCollectionRemoveExistingDataRespDto collectionRemoveExistingDataRes = null;
        if (queryPowerListRespDto != null) {
            CheckCollectionRemoveExistingDataReqDto collectionRemoveExistingDataReq = new CheckCollectionRemoveExistingDataReqDto();
            if (queryPowerListRespDto != null) {
                collectionRemoveExistingDataReq.setFrameworkPrivacyList(queryPowerListRespDto.getFrameworkPrivacyList());//sourceId:44313_1
            }
            if (queryPlfAuthListRespDto != null) {
                collectionRemoveExistingDataReq.setPlfAuthList(queryPlfAuthListRespDto.getPlfAuthList().stream().map(item -> item.getAuthorizedContentId())
                        .collect(Collectors.toList()));//sourceId:44314_1
            }

            /*D检查集合去除已存在数据[1547]  入参两个数据集，通过已存在标识字段匹配，去除第一个数据集中已存在的第二个数据集的数据 */

            collectionRemoveExistingDataRes = nbPlfAuth.checkCollectionRemoveExistingData(collectionRemoveExistingDataReq);

            collectionRemoveExistingDataRes_1 = collectionRemoveExistingDataRes;
        }

        BffQueryFilterPltPowerAuthListRespDto retData = new BffQueryFilterPltPowerAuthListRespDto();
        if (collectionRemoveExistingDataRes_1 != null) {
            retData.setFrameworkPrivacyList(collectionRemoveExistingDataRes_1.getFrameworkPrivacyList().stream().map(item -> BeanUtil.toBean(item, BffFrameworkPrivacyDto.class)).collect(Collectors.toList()));//sourceId:29912_1
        }


        return retData;
    }

    /**
     * B1-2查询可授权角色列表（平台）[1125]
     * gen by moon at 8/10/2022, 2:36:33 PM
     */
    @Trace(operationName = "B1-2查询可授权角色列表（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryFilterPltRoleAuthListRespDto queryFilterPltRoleAuthList(BffQueryFilterPltRoleAuthListReqDto reqDto) {


        AddCollectionRemoveExistingDataRespDto collectionRemoveExistingDataRes_1 = null;
//步骤0: D1-1查询平台授权范围列表 - queryPlfAuthList
        QueryPlfAuthListRespDto queryPlfAuthListRespDto = null;
        QueryPlfAuthListReqDto queryPlfAuthListReqDto = new QueryPlfAuthListReqDto();
        queryPlfAuthListReqDto.setTypeCode("ROLE");//sourceId:35247_1
        queryPlfAuthListReqDto.setIsArchive("FALSE");//sourceId:35249_1
        if (reqDto != null) {
            queryPlfAuthListReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35248_1
        }

        /*D1-1查询平台授权范围列表（已有）[580]   */
        Assert.isNull(queryPlfAuthListReqDto.getTypeCode(), "B1-2查询可授权角色列表（平台）-D1-1查询平台授权范围列表（已有）-授权内容类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReqDto.getAuthorizedObject(), "B1-2查询可授权角色列表（平台）-D1-1查询平台授权范围列表（已有）-授权对象ID不能为空", false);
        Assert.isNull(queryPlfAuthListReqDto.getIsArchive(), "B1-2查询可授权角色列表（平台）-D1-1查询平台授权范围列表（已有）-是否存档不能为空", false);
        queryPlfAuthListRespDto = fwBasePlfAuthClient.queryPlfAuthList(queryPlfAuthListReqDto).getData();


//步骤1: D1-2查询角色列表 - queryRoleList
        QueryRoleListRespDto queryRoleListRespDto = null;
        QueryRoleListReqDto queryRoleListReqDto = new QueryRoleListReqDto();
        queryRoleListReqDto.setPlatformData("TRUE");//sourceId:34190_1
        queryRoleListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:29824_1
        if (reqDto != null) {
            queryRoleListReqDto.setRoleType(reqDto.getRoleType());//sourceId:29818_1
        }

        /*D1-2查询角色列表（全部）[543]   */
        Assert.isNull(queryRoleListReqDto.getRoleType(), "B1-2查询可授权角色列表（平台）-D1-2查询角色列表（全部）-角色类型不能为空", false);
        Assert.isNull(queryRoleListReqDto.getPlatformData(), "B1-2查询可授权角色列表（平台）-D1-2查询角色列表（全部）-是否平台数据不能为空", false);
        Assert.isNull(queryRoleListReqDto.getSubjectLifeCycle(), "B1-2查询可授权角色列表（平台）-D1-2查询角色列表（全部）-主体生命周期不能为空", false);
        queryRoleListRespDto = fwBaseRoleClient.queryRoleList(queryRoleListReqDto).getData();


//步骤2: D授权角色/权限去除已存在 - addCollectionRemoveExistingData
        //ModelCode: collectionRemoveExistingData
        AddCollectionRemoveExistingDataRespDto collectionRemoveExistingDataRes = null;
        if (queryRoleListRespDto != null) {
            AddCollectionRemoveExistingDataReqDto collectionRemoveExistingDataReq = new AddCollectionRemoveExistingDataReqDto();
            if (queryRoleListRespDto != null) {
                for (FrameworkSceneRoleDto item : queryRoleListRespDto.getRoleList()) {
                    FrameworkSceneRoleDto oneItem = new FrameworkSceneRoleDto();
                    if (queryRoleListRespDto != null) {
                        oneItem.setRoleId(item.getRoleId());//sourceId:19006_2
                        oneItem.setRoleCode(item.getRoleCode());//sourceId:19007_2
                        oneItem.setRoleName(item.getRoleName());//sourceId:19008_2
                        oneItem.setIsIdentity(item.getIsIdentity());//sourceId:19009_2
                    }

                    collectionRemoveExistingDataReq.getRoleList().add(oneItem);
                }//sourceId:41022_1
            }
            if (queryPlfAuthListRespDto != null) {
                collectionRemoveExistingDataReq.setRoleIdList(queryPlfAuthListRespDto.getPlfAuthList().stream().map(item -> item.getAuthorizedContentId())
                        .collect(Collectors.toList()));//sourceId:86276_1
            }

            /*D授权角色/权限去除已存在[1512] collectionRemoveExistingData 入参两个数据集，通过已存在标识字段匹配，去除第一个数据集中已存在的第二个数据集的数据 */

            collectionRemoveExistingDataRes = nbPlfAuth.addCollectionRemoveExistingData(collectionRemoveExistingDataReq);

            collectionRemoveExistingDataRes_1 = collectionRemoveExistingDataRes;
        }

        BffQueryFilterPltRoleAuthListRespDto retData = new BffQueryFilterPltRoleAuthListRespDto();
        if (collectionRemoveExistingDataRes_1 != null) {
            retData.setRoleList(collectionRemoveExistingDataRes_1.getRoleList().stream().map(item -> BeanUtil.toBean(item, BffFrameworkSceneRoleDto.class)).collect(Collectors.toList()));//sourceId:41023_1
        }


        return retData;
    }

    /**
     * B1-1新增权限授权（平台）[594]
     * gen by moon at 8/10/2022, 3:40:44 AM
     */
    @Trace(operationName = "B1-1新增权限授权（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffAddPlfPowerAuthRespDto addPlfPowerAuth(BffAddPlfPowerAuthReqDto reqDto) {


        AddPlfAuthRespDto addPlfAuthRespDto_1 = null;
//步骤0: D1-1新增平台授权范围 - addPlfAuth
        AddPlfAuthRespDto addPlfAuthRespDto = null;
        AddPlfAuthReqDto addPlfAuthReqDto = new AddPlfAuthReqDto();
        addPlfAuthReqDto.setTypeCode("AUTH");//sourceId:35047_1
        addPlfAuthReqDto.setIsAutoEmpower("FALSE");//sourceId:35049_1
        addPlfAuthReqDto.setAuthorizeTypeCode("SENCE");//sourceId:35050_1
        if (reqDto != null) {
            addPlfAuthReqDto.setAuthorizedContentId(reqDto.getAuthorizedContentId());//sourceId:35048_1
            addPlfAuthReqDto.setIsView(reqDto.getIsView());//sourceId:35099_1
            addPlfAuthReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35051_1
            addPlfAuthReqDto.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//sourceId:35052_1
        }

        /*D1-1新增平台授权范围[582]   */
        Assert.isNull(addPlfAuthReqDto.getTypeCode(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-授权内容类型编码不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizedContentId(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-授权内容ID不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getIsAutoEmpower(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-是否自动授权不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getIsView(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-空间是否可见不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizeTypeCode(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-授权对象类型编码不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizedObject(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-授权对象ID不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getSubjectLifeCycle(), "B1-1新增权限授权（平台）-D1-1新增平台授权范围-主体生命周期不能为空", false);
        addPlfAuthRespDto = fwBasePlfAuthClient.addPlfAuth(addPlfAuthReqDto).getData();

        addPlfAuthRespDto_1 = addPlfAuthRespDto;

        BffAddPlfPowerAuthRespDto retData = new BffAddPlfPowerAuthRespDto();
        if (addPlfAuthRespDto_1 != null) {
            retData.setPlatformAuthorizeId(addPlfAuthRespDto_1.getPlatformAuthorizeId());//sourceId:35053_1
        }


        return retData;
    }

    /**
     * B1-1查询权限授权详情（平台）[593]
     * gen by moon at 8/10/2022, 3:40:43 AM
     */
    @Trace(operationName = "B1-1查询权限授权详情（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryPlfPowerAuthDetailRespDto queryPlfPowerAuthDetail(BffQueryPlfPowerAuthDetailReqDto reqDto) {


        QueryPlfPowerAuthDetailRespDto queryPlfPowerAuthDetailRespDto_1 = null;
        QueryInductionRecordInfoDetailComRespDto queryInductionRecordInfoDetailComRespDto_1 = null;
//步骤0: D1-1查询权限授权详情 - queryPlfPowerAuthDetail
        QueryPlfPowerAuthDetailRespDto queryPlfPowerAuthDetailRespDto = null;
        QueryPlfPowerAuthDetailReqDto queryPlfPowerAuthDetailReqDto = new QueryPlfPowerAuthDetailReqDto();
        if (reqDto != null) {
            queryPlfPowerAuthDetailReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:13326_1
        }

        /*D1-1查询权限授权详情[581] D1-2查询场景授权详情、获取创建人与冗余状态操作人就职记录ID用于下个虚拟用况接口的入参  */
        Assert.isNull(queryPlfPowerAuthDetailReqDto.getPlatformAuthorizeId(), "B1-1查询权限授权详情（平台）-D1-1查询权限授权详情-授权记录ID不能为空", false);
        queryPlfPowerAuthDetailRespDto = fwBasePlfAuthClient.queryPlfPowerAuthDetail(queryPlfPowerAuthDetailReqDto).getData();

        queryPlfPowerAuthDetailRespDto_1 = queryPlfPowerAuthDetailRespDto;

//步骤1: D1-3查询个人就职记录信息详情（公共） - queryInductionRecordInfoDetailCom
        QueryInductionRecordInfoDetailComRespDto queryInductionRecordInfoDetailComRespDto = null;
        if (queryPlfPowerAuthDetailRespDto != null) {
            QueryInductionRecordInfoDetailComReqDto queryInductionRecordInfoDetailComReqDto = new QueryInductionRecordInfoDetailComReqDto();
            if (queryPlfPowerAuthDetailRespDto != null) {
                queryInductionRecordInfoDetailComReqDto.setInductionRecordId(queryPlfPowerAuthDetailRespDto.getOperationInductionId());//sourceId:14511_1
            }

            /*D1-3查询个人就职记录信息详情（公共）[715]   */
            Assert.isNull(queryInductionRecordInfoDetailComReqDto.getInductionRecordId(), "B1-1查询权限授权详情（平台）-D1-3查询个人就职记录信息详情（公共）-就职记录ID不能为空", false);
            queryInductionRecordInfoDetailComRespDto = fwBaseInductionRecordClient.queryInductionRecordInfoDetailCom(queryInductionRecordInfoDetailComReqDto).getData();

            queryInductionRecordInfoDetailComRespDto_1 = queryInductionRecordInfoDetailComRespDto;
        }

        BffQueryPlfPowerAuthDetailRespDto retData = new BffQueryPlfPowerAuthDetailRespDto();
        if (queryPlfPowerAuthDetailRespDto_1 != null) {
            retData.setPlatformAuthorizeId(queryPlfPowerAuthDetailRespDto_1.getPlatformAuthorizeId());//sourceId:13446_1
            retData.setAuthorizedContentId(queryPlfPowerAuthDetailRespDto_1.getAuthorizedContentId());//sourceId:35231_1
            retData.setPrivacyCode(queryPlfPowerAuthDetailRespDto_1.getPrivacyCode());//sourceId:13465_1
            retData.setPrivacyName(queryPlfPowerAuthDetailRespDto_1.getPrivacyName());//sourceId:13459_1
            retData.setPrivacyLogo(queryPlfPowerAuthDetailRespDto_1.getPrivacyLogo());//sourceId:34286_1
            retData.setPrivacyIntroduce(queryPlfPowerAuthDetailRespDto_1.getPrivacyIntroduce());//sourceId:13460_1
            retData.setPrivacyType(queryPlfPowerAuthDetailRespDto_1.getPrivacyType());//sourceId:13462_1
            retData.setStrategyType(queryPlfPowerAuthDetailRespDto_1.getStrategyType());//sourceId:13463_1
            retData.setIsportPrivacy(queryPlfPowerAuthDetailRespDto_1.getIsportPrivacy());//sourceId:44215_1
            retData.setPrivacyRoute(queryPlfPowerAuthDetailRespDto_1.getPrivacyRoute());//sourceId:13464_1
            retData.setIsDataPrivacy(queryPlfPowerAuthDetailRespDto_1.getIsDataPrivacy());//sourceId:44216_1
            retData.setDataModel(queryPlfPowerAuthDetailRespDto_1.getDataModel());//sourceId:34289_1
            retData.setPrivacyCategory(queryPlfPowerAuthDetailRespDto_1.getPrivacyCategory());//sourceId:44217_1
            retData.setBusinessPurposes(queryPlfPowerAuthDetailRespDto_1.getBusinessPurposes());//sourceId:44218_1
            retData.setIsView(queryPlfPowerAuthDetailRespDto_1.getIsView());//sourceId:34287_1
            retData.setIsDefault(queryPlfPowerAuthDetailRespDto_1.getIsDefault());//sourceId:34288_1
            retData.setSubjectLifeCycle(queryPlfPowerAuthDetailRespDto_1.getSubjectLifeCycle());//sourceId:13449_1
            retData.setOperationInductionId(queryPlfPowerAuthDetailRespDto_1.getOperationInductionId());//sourceId:13450_1
            retData.setOperateTime(queryPlfPowerAuthDetailRespDto_1.getOperateTime());//sourceId:13451_1
        }
        if (queryInductionRecordInfoDetailComRespDto_1 != null) {
            retData.setUserId(queryInductionRecordInfoDetailComRespDto_1.getUserId());//sourceId:14518_1
            retData.setIdCardName(queryInductionRecordInfoDetailComRespDto_1.getIdCardName());//sourceId:14519_1
            retData.setNickName(queryInductionRecordInfoDetailComRespDto_1.getNickName());//sourceId:14520_1
            retData.setUserFace(queryInductionRecordInfoDetailComRespDto_1.getUserFace());//sourceId:14521_1
        }


        return retData;
    }

    /**
     * B1-1查询权限授权列表（平台）[592]
     * gen by moon at 8/20/2022, 6:00:12 PM
     */
    @Trace(operationName = "B1-1查询权限授权列表（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryPlfPowerAuthListRespDto queryPlfPowerAuthList(BffQueryPlfPowerAuthListReqDto reqDto) {


        QueryPlfPowerAuthListRespDto queryPlfPowerAuthListRespDto_1 = null;
        BatchQueryInductionRecordListComRespDto batchQueryInductionRecordListComRespDto_1 = null;
//步骤0: D1-1查权限授权列表 - queryPlfPowerAuthList
        QueryPlfPowerAuthListRespDto queryPlfPowerAuthListRespDto = null;
        QueryPlfPowerAuthListReqDto queryPlfPowerAuthListReqDto = new QueryPlfPowerAuthListReqDto();
        if (reqDto != null) {
            queryPlfPowerAuthListReqDto.setPrivacyType(reqDto.getPrivacyType());//sourceId:34259_1
            queryPlfPowerAuthListReqDto.setIsArchive(reqDto.getIsArchive());//sourceId:34258_1
            queryPlfPowerAuthListReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:34257_1
        }

        /*D1-1查权限授权列表[1428]   */
        Assert.isNull(queryPlfPowerAuthListReqDto.getIsArchive(), "B1-1查询权限授权列表（平台）-D1-1查权限授权列表-是否存档不能为空", false);
        Assert.isNull(queryPlfPowerAuthListReqDto.getAuthorizedObject(), "B1-1查询权限授权列表（平台）-D1-1查权限授权列表-授权对象ID不能为空", false);
        queryPlfPowerAuthListRespDto = fwBasePlfAuthClient.queryPlfPowerAuthList(queryPlfPowerAuthListReqDto).getData();

        queryPlfPowerAuthListRespDto_1 = queryPlfPowerAuthListRespDto;

//步骤1: D1-3批量查询就职记录列表（公共） - batchQueryInductionRecordListCom
        BatchQueryInductionRecordListComRespDto batchQueryInductionRecordListComRespDto = null;
        if (queryPlfPowerAuthListRespDto != null && queryPlfPowerAuthListRespDto != null && queryPlfPowerAuthListRespDto.getPlfAuthList() != null && queryPlfPowerAuthListRespDto.getPlfAuthList().size() > 0) {
            BatchQueryInductionRecordListComReqDto batchQueryInductionRecordListComReqDto = new BatchQueryInductionRecordListComReqDto();
            if (queryPlfPowerAuthListRespDto != null) {
                batchQueryInductionRecordListComReqDto.setPerOrgInductionRecordList(queryPlfPowerAuthListRespDto.getPlfAuthList().stream().map(item -> item.getOperationInductionId())
                        .collect(Collectors.toList()));//sourceId:31832_1
            }

            /*D1-3批量查询就职记录列表（公共）[602]   */

            batchQueryInductionRecordListComRespDto = fwBaseInductionRecordClient.batchQueryInductionRecordListCom(batchQueryInductionRecordListComReqDto).getData();

            batchQueryInductionRecordListComRespDto_1 = batchQueryInductionRecordListComRespDto;
        }

        BffQueryPlfPowerAuthListRespDto retData = new BffQueryPlfPowerAuthListRespDto();
        //数据集融合
        if (queryPlfPowerAuthListRespDto_1 != null && !CollectionUtil.isEmpty(queryPlfPowerAuthListRespDto_1.getPlfAuthList())) {
            for (PlfAuthDto plfAuthDto : queryPlfPowerAuthListRespDto_1.getPlfAuthList()) {
                BffPlfAuthDto retElm = new BffPlfAuthDto();
                if (queryPlfPowerAuthListRespDto_1 != null) {
                    retElm.setPlatformAuthorizeId(plfAuthDto.getPlatformAuthorizeId());//sourceId:15502_2
                    retElm.setAuthorizedContentId(plfAuthDto.getAuthorizedContentId());//sourceId:15503_2
                    retElm.setPrivacyCode(plfAuthDto.getPrivacyCode());//sourceId:15507_2
                    retElm.setPrivacyName(plfAuthDto.getPrivacyName());//sourceId:15509_2
                    retElm.setSubjectLifeCycle(plfAuthDto.getSubjectLifeCycle());//sourceId:15504_2
                    retElm.setOperationInductionId(plfAuthDto.getOperationInductionId());//sourceId:15505_2
                    retElm.setOperateTime(plfAuthDto.getOperateTime());//sourceId:15506_2
                }
                retData.getPlfAuthList().add(retElm);
                if (batchQueryInductionRecordListComRespDto_1 != null) {
                    for (PerOrgInductionRecordDto perOrgInductionRecordDto : batchQueryInductionRecordListComRespDto_1.getPerOrgInductionRecordList()) {
                        if (perOrgInductionRecordDto.getInductionRecordId().equals(plfAuthDto.getOperationInductionId())) {
                            if (batchQueryInductionRecordListComRespDto_1 != null) {
                                retElm.setUserId(perOrgInductionRecordDto.getUserId());//sourceId:38758_2
                                retElm.setUserFace(perOrgInductionRecordDto.getUserFace());//sourceId:38761_2
                                retElm.setIdCardName(perOrgInductionRecordDto.getIdCardName());//sourceId:38759_2
                                retElm.setNickName(perOrgInductionRecordDto.getNickName());//sourceId:38760_2
                            }
                        }
                    }
                }

            }
        }//sourceId:34261_1


        retData.setPageNum(queryPlfPowerAuthListRespDto.getPageNum());
        retData.setPageSize(queryPlfPowerAuthListRespDto.getPageSize());
        retData.setTotal(queryPlfPowerAuthListRespDto.getTotalNum());
        retData.setIsLastPage((Math.ceil(Double.valueOf(queryPlfPowerAuthListRespDto.getTotalNum()) / Double.valueOf(queryPlfPowerAuthListRespDto.getPageSize()))) <= retData.getPageNum());


        return retData;
    }

    /**
     * B1-1存档角色授权（平台）[588]
     * gen by moon at 8/30/2022, 12:00:59 AM
     */
    @Trace(operationName = "B1-1存档角色授权（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffArchivePltRoleAuthRespDto archivePltRoleAuth(BffArchivePltRoleAuthReqDto reqDto) {


        //步骤0: D1-1存档平台角色授权 - archivePltRoleAuth
        ArchivePltRoleAuthRespDto archivePltRoleAuthRespDto = null;
        ArchivePltRoleAuthReqDto archivePltRoleAuthReqDto = new ArchivePltRoleAuthReqDto();
        if (reqDto != null) {
            archivePltRoleAuthReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:45125_1
        }

        /*D1-1存档平台角色授权[583]   */
        Assert.isNull(archivePltRoleAuthReqDto.getPlatformAuthorizeId(), "B1-1存档角色授权（平台）-D1-1存档平台角色授权-授权记录ID不能为空", false);
        archivePltRoleAuthRespDto = fwBasePlfAuthClient.archivePltRoleAuth(archivePltRoleAuthReqDto).getData();


//步骤1: D1-1查询角色授权详情 - queryPltRoleAuthDetail
        QueryPltRoleAuthDetailRespDto queryPltRoleAuthDetailRespDto = null;
        QueryPltRoleAuthDetailReqDto queryPltRoleAuthDetailReqDto = new QueryPltRoleAuthDetailReqDto();
        if (reqDto != null) {
            queryPltRoleAuthDetailReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:51568_1
        }

        /*D1-1查询角色授权详情[1255]   */
        Assert.isNull(queryPltRoleAuthDetailReqDto.getPlatformAuthorizeId(), "B1-1存档角色授权（平台）-D1-1查询角色授权详情-授权记录ID不能为空", false);
        queryPltRoleAuthDetailRespDto = fwBasePlfAuthClient.queryPltRoleAuthDetail(queryPltRoleAuthDetailReqDto).getData();


//步骤2: D1-2查询角色人员列表 - queryRoleRelList
        QueryRoleRelListRespDto queryRoleRelListRespDto = null;
        Assert.isTrue(queryPltRoleAuthDetailRespDto == null || queryPltRoleAuthDetailRespDto.getRoleId() == null, "返回值不能为空", false);
        if (queryPltRoleAuthDetailRespDto != null) {
            QueryRoleRelListReqDto queryRoleRelListReqDto = new QueryRoleRelListReqDto();
            queryRoleRelListReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:278031_1
            if (queryPltRoleAuthDetailRespDto != null) {
                queryRoleRelListReqDto.setRoleId(queryPltRoleAuthDetailRespDto.getRoleId());//sourceId:51604_1
            }

            /*D1-2查询角色人员列表[1134]   */
            Assert.isNull(queryRoleRelListReqDto.getRoleId(), "B1-1存档角色授权（平台）-D1-2查询角色人员列表-角色ID不能为空", false);
            Assert.isNull(queryRoleRelListReqDto.getSpaceId(), "B1-1存档角色授权（平台）-D1-2查询角色人员列表-创建于空间ID不能为空", false);
            queryRoleRelListRespDto = fwBaseMemberClient.queryRoleRelList(queryRoleRelListReqDto).getData();


        }

//步骤3: Redis批量清空用户信息 - batchClearUserInfoFromRedis
        //ModelCode: batchClearUserInfoFromRedis
        BatchClearUserInfoFromRedisRespDto batchClearUserInfoFromRedisRes = null;
        if (queryRoleRelListRespDto != null && queryRoleRelListRespDto != null && queryRoleRelListRespDto.getRoleRelList() != null && queryRoleRelListRespDto.getRoleRelList().size() > 0) {
            BatchClearUserInfoFromRedisReqDto batchClearUserInfoFromRedisReq = new BatchClearUserInfoFromRedisReqDto();
            if (queryRoleRelListRespDto != null) {
                batchClearUserInfoFromRedisReq.setBeginMemberList(queryRoleRelListRespDto.getRoleRelList().stream().map(item -> item.getOriginalRoleMemberId())
                        .collect(Collectors.toList()));//sourceId:51607_1
            }

            /*Redis批量清空用户信息[1713]  入参身份ID数据集，清除用户就职信息缓存 */

            batchClearUserInfoFromRedisRes = nbPlfAuth.batchClearUserInfoFromRedis(batchClearUserInfoFromRedisReq);


        }

        BffArchivePltRoleAuthRespDto retData = new BffArchivePltRoleAuthRespDto();


        return retData;
    }

    /**
     * B1-1新增角色授权（平台）[587]
     * gen by moon at 8/10/2022, 3:40:39 AM
     */
    @Trace(operationName = "B1-1新增角色授权（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffAddPltRoleAuthRespDto addPltRoleAuth(BffAddPltRoleAuthReqDto reqDto) {


        AddPlfAuthRespDto addPlfAuthRespDto_1 = null;
//步骤0: D1-1新增平台授权范围 - addPlfAuth
        AddPlfAuthRespDto addPlfAuthRespDto = null;
        AddPlfAuthReqDto addPlfAuthReqDto = new AddPlfAuthReqDto();
        addPlfAuthReqDto.setTypeCode("ROLE");//sourceId:35109_1
        addPlfAuthReqDto.setIsAutoEmpower("FALSE");//sourceId:35111_1
        addPlfAuthReqDto.setAuthorizeTypeCode("SENCE");//sourceId:35113_1
        if (reqDto != null) {
            addPlfAuthReqDto.setAuthorizedContentId(reqDto.getAuthorizedContentId());//sourceId:35110_1
            addPlfAuthReqDto.setIsView(reqDto.getIsView());//sourceId:35112_1
            addPlfAuthReqDto.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35114_1
            addPlfAuthReqDto.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//sourceId:35115_1
        }

        /*D1-1新增平台授权范围[582]   */
        Assert.isNull(addPlfAuthReqDto.getTypeCode(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-授权内容类型编码不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizedContentId(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-授权内容ID不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getIsAutoEmpower(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-是否自动授权不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getIsView(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-空间是否可见不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizeTypeCode(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-授权对象类型编码不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getAuthorizedObject(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-授权对象ID不能为空", false);
        Assert.isNull(addPlfAuthReqDto.getSubjectLifeCycle(), "B1-1新增角色授权（平台）-D1-1新增平台授权范围-主体生命周期不能为空", false);
        addPlfAuthRespDto = fwBasePlfAuthClient.addPlfAuth(addPlfAuthReqDto).getData();

        addPlfAuthRespDto_1 = addPlfAuthRespDto;

        BffAddPltRoleAuthRespDto retData = new BffAddPltRoleAuthRespDto();
        if (addPlfAuthRespDto_1 != null) {
            retData.setPlatformAuthorizeId(addPlfAuthRespDto_1.getPlatformAuthorizeId());//sourceId:35120_1
        }


        return retData;
    }

    /**
     * B1-1查询角色授权详情（平台）[586]
     * gen by moon at 8/10/2022, 3:40:38 AM
     */
    @Trace(operationName = "B1-1查询角色授权详情（平台）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryPltRoleAuthDetailRespDto queryPltRoleAuthDetail(BffQueryPltRoleAuthDetailReqDto reqDto) {


        QueryPltRoleAuthDetailRespDto queryPltRoleAuthDetailRespDto_1 = null;
        QueryInductionRecordInfoDetailComRespDto queryInductionRecordInfoDetailComRespDto_1 = null;
//步骤0: D1-1查询角色授权详情 - queryPltRoleAuthDetail
        QueryPltRoleAuthDetailRespDto queryPltRoleAuthDetailRespDto = null;
        QueryPltRoleAuthDetailReqDto queryPltRoleAuthDetailReqDto = new QueryPltRoleAuthDetailReqDto();
        if (reqDto != null) {
            queryPltRoleAuthDetailReqDto.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:29029_1
        }

        /*D1-1查询角色授权详情[1255]   */
        Assert.isNull(queryPltRoleAuthDetailReqDto.getPlatformAuthorizeId(), "B1-1查询角色授权详情（平台）-D1-1查询角色授权详情-授权记录ID不能为空", false);
        queryPltRoleAuthDetailRespDto = fwBasePlfAuthClient.queryPltRoleAuthDetail(queryPltRoleAuthDetailReqDto).getData();

        queryPltRoleAuthDetailRespDto_1 = queryPltRoleAuthDetailRespDto;

//步骤1: D1-3查询个人就职记录信息详情（公共） - queryInductionRecordInfoDetailCom
        QueryInductionRecordInfoDetailComRespDto queryInductionRecordInfoDetailComRespDto = null;
        if (queryPltRoleAuthDetailRespDto != null) {
            QueryInductionRecordInfoDetailComReqDto queryInductionRecordInfoDetailComReqDto = new QueryInductionRecordInfoDetailComReqDto();
            if (queryPltRoleAuthDetailRespDto != null) {
                queryInductionRecordInfoDetailComReqDto.setInductionRecordId(queryPltRoleAuthDetailRespDto.getOperationInductionId());//sourceId:14522_1
            }

            /*D1-3查询个人就职记录信息详情（公共）[715]   */
            Assert.isNull(queryInductionRecordInfoDetailComReqDto.getInductionRecordId(), "B1-1查询角色授权详情（平台）-D1-3查询个人就职记录信息详情（公共）-就职记录ID不能为空", false);
            queryInductionRecordInfoDetailComRespDto = fwBaseInductionRecordClient.queryInductionRecordInfoDetailCom(queryInductionRecordInfoDetailComReqDto).getData();

            queryInductionRecordInfoDetailComRespDto_1 = queryInductionRecordInfoDetailComRespDto;
        }

        BffQueryPltRoleAuthDetailRespDto retData = new BffQueryPltRoleAuthDetailRespDto();
        if (queryPltRoleAuthDetailRespDto_1 != null) {
            retData.setPlatformAuthorizeId(queryPltRoleAuthDetailRespDto_1.getPlatformAuthorizeId());//sourceId:34164_1
            retData.setRoleLogo(queryPltRoleAuthDetailRespDto_1.getRoleLogo());//sourceId:34176_1
            retData.setRoleName(queryPltRoleAuthDetailRespDto_1.getRoleName());//sourceId:34178_1
            retData.setRoleId(queryPltRoleAuthDetailRespDto_1.getRoleId());//sourceId:34175_1
            retData.setRoleCode(queryPltRoleAuthDetailRespDto_1.getRoleCode());//sourceId:34177_1
            retData.setOperationInductionId(queryPltRoleAuthDetailRespDto_1.getOperationInductionId());//sourceId:34173_1
            retData.setOperateTime(queryPltRoleAuthDetailRespDto_1.getOperateTime());//sourceId:34174_1
            retData.setSubjectLifeCycle(queryPltRoleAuthDetailRespDto_1.getSubjectLifeCycle());//sourceId:34172_1
            retData.setIsAutoEmpower(queryPltRoleAuthDetailRespDto_1.getIsAutoEmpower());//sourceId:34170_1
            retData.setIsView(queryPltRoleAuthDetailRespDto_1.getIsView());//sourceId:34171_1
            retData.setIsDefault(queryPltRoleAuthDetailRespDto_1.getIsDefault());//sourceId:34169_1
            retData.setHostTypeName(queryPltRoleAuthDetailRespDto_1.getHostTypeName());//sourceId:34185_1
            retData.setHostTypeId(queryPltRoleAuthDetailRespDto_1.getHostTypeId());//sourceId:34184_1
            retData.setRoleType(queryPltRoleAuthDetailRespDto_1.getRoleType());//sourceId:34179_1
            retData.setIsIdentity(queryPltRoleAuthDetailRespDto_1.getIsIdentity());//sourceId:34180_1
            retData.setAutomaticCreation(queryPltRoleAuthDetailRespDto_1.getAutomaticCreation());//sourceId:34181_1
            retData.setPlatformData(queryPltRoleAuthDetailRespDto_1.getPlatformData());//sourceId:34182_1
            retData.setRoleRemark(queryPltRoleAuthDetailRespDto_1.getRoleRemark());//sourceId:34183_1
        }
        if (queryInductionRecordInfoDetailComRespDto_1 != null) {
            retData.setUserFace(queryInductionRecordInfoDetailComRespDto_1.getUserFace());//sourceId:34189_1
            retData.setIdCardName(queryInductionRecordInfoDetailComRespDto_1.getIdCardName());//sourceId:34187_1
            retData.setNickName(queryInductionRecordInfoDetailComRespDto_1.getNickName());//sourceId:34188_1
            retData.setUserId(queryInductionRecordInfoDetailComRespDto_1.getUserId());//sourceId:34186_1
        }


        return retData;
    }
    //
}
